/**
 * @author AIUHD74
 */


var orderQueue = new Array();
var timer = 1;

// turn on timer variable
setInterval(function() {
	orderTimer();
}, 5000);



function orderTimer() {
	//if timer variable is on then add orders
	if (timer == 1) {
		addOrders();
	}
}

function addOrders() {
	if (selectedMenuQueue.length > 0 && hiredEmployeeQueue.length > 0) {
		//place random order
		var rand = Math.floor((Math.random() * 5) + 1);
		for (var i = 0; i < rand; i++) {
			var rand2 = Math.floor((Math.random() * selectedMenuQueue.length) + 0);
			orderQueue.push(selectedMenuQueue[rand2]);
			var date = getDate();
			writeToConsole("added " + selectedMenuQueue[rand2] + " to the order queue @ " + date);
		}
	}
	//consumeOrder();
}

function consumeOrder() {
	if (orderQueue.length > 0) {
		for (var i = 0; i < orderQueue.length; i++) {
			objx(sandwiches).each(function(item) {
				var currItem = item.Name;
				if (item.Name == orderQueue[i]) {
					var date = getDate();
					var totalCost = calcCost(item.Ingredients);
					writeToConsole("Consumed order:" + orderQueue[i] + " @ " + date);
					money = money + (parseFloat(item.Price) - totalCost);
					//writeToConsole("you now have " + money);
					writeToConsole("Price:" + parseFloat(item.Price) + " " + "Cost:" + totalCost + " " + "Profit:" + (parseFloat(item.Price) - totalCost));
					updateMoney();
				}
			});
		}
		for (var i = 0; i < orderQueue.length; i++) {
			orderQueue.pop();
		}
	}
}

